<?

//Initiate Authenticate
SecurityRedirect ();

//echo "<pre>"; print_r($_SESSION);

//initiate Vars
define("PRIMARY_KEY","nobkt");
$KEY[]         = array("PRIMARY_KEY"=>PRIMARY_KEY);
$FileName      = "ais_transaction_adventry_oth_mrkt.php";
$FileTemplate  = "ais_transaction_adventry_oth_mrkt_list.html";
$TableName     = "ais_advance";
$SubHeaderTitle= "Transaction Advance - Entry Advance Marketing Other";
$PageSize      = 10 ;
$HTMLGridList  = "AdvanceGrid";

//************ FORM ACTION **************
    if (GetParam("Action","")=="Delete") {
        DeleteRecord ("txtCheck",$PageSize);
    }

//Initiate Database Table For Search;
$FCode = GetParam("advcodeSearch","");
$JOCode = GetParam("jocodeSearch","");
//$FSkada = GetParam("skadaSearch","");
//$FDept = GetParam("deptSearch","");
$QueryGet  = GetQueryString("All", array('PageNum'));
//******* DATABASE FORM QUERY ***********
//$SQL = "SELECT *, sum(jumlah) as sumjumlah FROM `$TableName` ";
$SQL = "SELECT *, sum(jumlah) as sumjumlah FROM `$TableName` a ";

$SQLCount = "SELECT count(*) FROM `$TableName` ";
//$WHERE  = "ktrasl='".GetOfficeID()."' AND bs_ref='OTH' AND ".QueryLedger();
$WHERE  = "ktrasl='".GetOfficeID()."' AND bs_ref='OTH' ";

//SELECT *, sum(amount) as sumjumlah FROM `ais_advance` a
//JOIN tbljoborder_costing b ON a.jo_costing_id = b.jo_costing_id WHERE ktrasl='000' AND (1) GROUP BY nobkt ORDER BY tglbkt DESC, nobkt DESC

//Retrieve Parameter from search
if ($FCode) {
    $CustomWhere = " nobkt like '%".$FCode."%' ";
    if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
    else $WHERE = $CustomWhere;
}

if ($JOCode) {
    $CustomWhere = " jo_code like '%".$JOCode."%' ";
    if (strlen($WHERE)) $WHERE .= " AND ".$CustomWhere;
    else $WHERE = $CustomWhere;
}

if (strlen($WHERE)) {
    $SQL = $SQL."WHERE a.bs_ref = 'OTH' AND a.bs_progress != 'cancel' AND ".$WHERE;
    $SQLCount = $SQLCount."WHERE a.bs_ref = 'OTH' AND a.bs_progress != 'cancel' AND ".$WHERE;
} else $SQL = $SQL;
$SQL = $SQL." GROUP BY nobkt";
$SQL .= " ORDER BY tglbkt DESC, nobkt DESC";
//print $SQL;
//Select Customer
//$SQLDept = "SELECT * FROM tbldept";

//******* SHOW FORM CONTENT *********
$PageNum = 1;
/*
$RecCnt = $DBConnection->dbc->get_var($SQLCount) ;
*/
if (GetParam("PageNum","")) $PageNum  = GetParam("PageNum","");

//Default value
if (!isset($_GET)) $_GET=&$HTTP_GET_VARS ;
if (isset($_GET['PageNum'])) {
  $PageNum = $_GET['PageNum'] ;
} else {
    $PageNum = 1 ;
}

//Default value
if (isset($_GET['RecCnt'])) {
  $RecCnt = intval($_GET['RecCnt']) ;
} else {
    $RecCnt = -1 ;
}

$TBS = new clsTinyButStrong ;
$TBS->LoadTemplate($MOD_TEMPLATE_DIR."/".$FileTemplate);
$TBS->MergeBlock("bln",$KEY);
$RecCnt = $TBS->MergeBlock("blg",$DBMysql,$SQL,$PageSize,$PageNum,$RecCnt);
//$TBS->MergeBlock("deptblk",$DBMysql,$SQLDept);
$TBS->MergeNavigationBar('nv',array('size'=>10,'pos'=>'centred'),$PageNum,$RecCnt,$PageSize);
$TBS->Show();

function DeleteRecord ($sequence_name,$PageSize) {
    global $DBConnection,$FileName,$TableName;
    for ($x=1;$x<=$PageSize;$x++) {
        if (GetParam($sequence_name.$x,"")) {
            $DBConnection->Delete("$TableName",$sequence_name.$x);
        }
    }
    header("Location: $FileName");
    exit;
}

?>
